package com.beiye.drivertransport.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.beiye.drivertransport.R;
import com.beiye.drivertransport.bean.LearnRecordBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by ky on 2018/1/29.
 */

public class MyGridViewAdapter extends BaseAdapter {

    private Context mContext;

    /**
     * 每个分组下的每个子项的 GridView 数据集合
     */
    private List<LearnRecordBean.RowsBean.PhotoListBean> itemGridList;

    public MyGridViewAdapter(Context mContext, List<LearnRecordBean.RowsBean.PhotoListBean> itemGridList) {
        this.mContext = mContext;
        this.itemGridList = itemGridList;
    }

    @Override
    public int getCount() {
        return itemGridList.size();
    }

    @Override
    public Object getItem(int position) {
        return itemGridList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (null == convertView) {
            convertView = View.inflate(mContext, R.layout.gridview_item, null);
        }
        ImageView img_gv = (ImageView) convertView.findViewById(R.id.img_parent);
        String url = itemGridList.get(position).getUrl();

        Picasso.with(mContext).load(Uri.parse(url)).placeholder(R.mipmap.no_data).into(img_gv);
        return convertView;
    }
}